const router = require("express").Router();
const multer =require("multer");
// const upload = multer({ dest: "public/upload"})

const storage = multer.diskStorage({
  //保存路径
  destination: function (req, file, cb) {
    cb(null, 'public/upload')
    //注意这里的文件路径,不是相对路径，直接填写从项目根路径开始写就行了
  },
  //保存在 destination 中的文件名
  filename: function (req, file, cb) {    
    cb(null, file.originalname)
  }
})
const upload = multer({ storage: storage })

router.post("/upload",upload.single("file"),(req, res) => {
	res.status(200).json({
    code:200,
    msg:"上传成功！",
    data:'http://localhost:8080/'+"upload/"+req.file.originalname
  });
});
module.exports = router;